stage.set_background("halfcourt")
sprite = codesters.Sprite("player1")
sprite.go_to(-175, -150)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
stage.set_gravity(10)
sprite.set_gravity_off()
def click(sprite):
sprite.say("Hello, name")
# add other actions...
sprite.event_click(click)
t = codesters.Teacher()
says = t.find_function("say")
sprites = t.find_function("Sprite")
tval1 = len(says)
try:
tval2 = sprites[2][1].replace(" ", "")
tval3 = t.get_indent_at_line(sprites[2][0])
except:
tval2 = "DNE"
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == 0, "Great job!")
t1.add_failure(tval1 > 0, "Oops! Your program should have no say commands.")
t2 = TestObjective()
t2.add_success("basketball" in tval2, "Great job!")
t2.add_failure(tval2 == "DNE", "Did you drag in Basketball inside your click event?")
t2.add_creative("basketball" not in tval2 and tval2 != "DNE", "That's a good sprite, too!")
t3 = TestObjective()
t3.add_success(tval3 == 4, "Great job!")
t3.add_failure(tval3 == 0, 'Oops! Did you forget to indent codesters.Sprite("basketball")?')
t3.add_failure(tval3 > 4, 'Oops! Did you indent your codesters.Sprite("basketball") command too many times?')
t3.add_failure(tval3 == "DNE", 'Did you drag in Basketball inside your click event?')
t4 = TestObjective()
t4.add_success("ball=" in tval2, "Great job!")
t4.add_failure("sprite=" in tval2, "Did you change the variable name from sprite to ball?")
t4.add_failure(tval2 == "DNE", "Did you drag in Basketball inside your click event?")
t4.add_failure("ball=" not in tval2, "Oops! Make sure you rename the variable of your basketball sprite to ball.")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)